﻿#include <algorithm>
#include <gtest/gtest.h>
#include <iostream>
#include <vector>

#include <learn/alg/alg_dynamic_curve.h>
#include <learn/alg/alg_dynamic_surface.h>
#include <learn/geom/geom_bezier_curve.h>
#include <learn/math/polynomial.h>

using namespace xi;
using namespace xi::geom;
using namespace xi::alg;

TEST(TestAlgDynamic, dynamic_curve)
{
    {
        std::vector<Vec3> poles(4);
        poles[0] = Vec3{0.0, 0.0, 0.0};
        poles[1] = Vec3{0.0, 1.0, 0.0};
        poles[2] = Vec3{1.0, 1.0, 1.0};
        poles[3] = Vec3{1.0, 0.0, 0.0};

        Alg_DynamicBezierCurve<3> curve(poles, 0.01);
        std::shared_ptr<Geom_BezierCurve<3>> bez(new Geom_BezierCurve<3>(std::move(poles), 3));

        EXPECT_LE((bez->value(0.8) - curve.evaluate(0.8).back()).modulus(), Numeric::epsilon);
    }

    {
        std::vector<Vec3> poles(4);
        poles[0] = Vec3{0.0, 0.0, 0.0};
        poles[1] = Vec3{0.0, 1.0, 0.0};
        poles[2] = Vec3{1.0, 1.0, 1.0};
        poles[3] = Vec3{1.0, 0.0, 0.0};

        Alg_DynamicPowerCurve<3> curve(poles, 0.01);
        Polynomial<Vec3, double> bez(std::move(poles));

        EXPECT_LE((bez.value(0.8) - curve.evaluate(0.8).back()).modulus(), Numeric::epsilon);
    }
}

TEST(TestAlgDynamic, dynamic_surface)
{
}
